<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title></title>
	<#include "/common/commoncss.ftl">
	<link rel="stylesheet" type="text/css"
		  href="bootstrap/css/bootstrap.min.css" />
	<link rel="stylesheet" type="text/css" href="css/common/box.css" />
	<style type="text/css">
		a {
			color: black;
		}

		a:hover {
			text-decoration: none;
		}

		.bgc-w {
			background-color: #fff;
		}
	</style>
</head>

<body style="background-color: #ecf0f5;">
<div class="row" style="padding-top: 10px;">
	<div class="col-md-2">
		<h1 style="font-size: 24px; margin: 0;" class="">部门管理</h1>
	</div>
	<div class="col-md-10 text-right">
		<a href="##"><span class="glyphicon glyphicon-home"></span> 首页</a> >
		<a disabled="disabled">部门管理</a>
	</div>
</div>
<div class="col-md-12 thistable" >
	<!--id="container"-->
	<#include "/user/deptmanagetable.ftl">
</div>

<div class="modal fade in userchange" id="thismodal" data-backdrop="static">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-body box no-padding" style="display: none;">
				<form action="deptandpositionchange" method="post">
					<div class="box-header">
						<h3 class="box-title mc-title" style="font-size:15px;">人事变动</h3>
					</div>
					<div class="box-body no-padding">
						<div class="row">
							<div class="changeuser">
								<input class="changeuserid" type="hidden" name="userid" value=""/>
								<input type="hidden" name="deptid" value="${(dept.deptId)!''}">
							</div>
							<div class="col-md-6">
								<label class="control-label"> <span>部门</span></label>
								<select class="deptselect form-control" name="changedeptid">
									<#list depts as dept0>
										<#if dept0.deptName??>
											<#if dept0.deptId == dept.deptId>
												<option selected value="${dept0.deptId}">${dept0.deptName}</option>
											<#else>
												<option value="${dept0.deptId}">${dept0.deptName}</option>
											</#if>
										</#if>
									</#list>
								</select>
							</div>
							<div class="col-md-6">
								<label class="control-label"> <span>职位</span></label>
								<select class="positionselect form-control" name="positionid">
									<#if positions ??>
										<#list positions as position>
											<option value="${position.positionId}">${position.name}</option>
										</#list>
									</#if>
								</select>
							</div>
						</div>

					</div>
					<div class="box-footer" style="text-align:right;">
						<button type="submit" class="btn btn-primary"
						>确定</button>
						<button type="button" class="btn btn-default mcmodalcancle"
								data-dismiss="modal">取消</button>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>
<div class="modal fade in managechangemodel" id="thismodal" data-backdrop="static">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-body box no-padding" style="display: none;">
				<form action="deptmanagerchange" method="post">
					<div class="box-header">
						<h3 class="box-title mc-title" style="font-size:15px;">人事变动</h3>
					</div>
					<div class="box-body no-padding">
						<div class="row">

							<#if deptmanage??>
                                <div class="col-md-12">
                                    <label class="control-label" style="margin-top: 5px"> <span>当前经理去向：</span></label>
                                    <input type="hidden" name="deptid" value="${(dept.deptId)!''}">
                                    <input type="hidden" name="oldmanageid" value="${deptmanage.userId}" />
                                </div>
                                <div class="col-md-6">
                                    <label class="control-label"> <span>部门</span></label>
                                    <select class="deptselect form-control" name="changedeptid">
                                        <#list depts as dept0>
                                            <#if dept0.deptName??>
                                                <#if dept0.deptId == dept.deptId>
                                                    <option selected value="${dept0.deptId}">${dept0.deptName}</option>
                                                <#else>
                                                    <option value="${dept0.deptId}">${dept0.deptName}</option>
                                                </#if>
                                            </#if>
                                        </#list>
                                    </select>
                                </div>
                                <div class="col-md-6">
                                    <label class="control-label"> <span>职位</span></label>
                                    <select class="positionselect form-control" name="positionid">
                                        <#if positions ??>
                                            <#list positions as position>
                                                <option value="${position.positionId}">${position.name}</option>
                                            </#list>
                                        </#if>
                                    </select>
                                </div>
                                <div class="col-md-6">
                                    <#if deptuser?? & deptuser?size gt 0>
                                        <label class="control-label" style="margin-top: 5px"> <span>新任部门经理：</span></label>
                                        <select class="form-control" name="newmanageid">
                                            <option></option>
                                            <#list aoaUsers as user>
                                                <option value="${user.userId}">${user.realName}</option>
                                            </#list>
                                        </select>
                                    </#if>
                                </div>
                            <#else>
                                <div class="col-md-6">
                                    <input type="hidden" name="deptid" value="${(dept.deptId)!''}">
                                    <label class="control-label" style="margin-top: 5px"> <span>新任部门经理：</span></label>
                                    <select class="form-control" name="newmanageid">
                                        <#list aoaUsers as user>
                                            <option value="${user.userId}">${user.realName}</option>
                                        </#list>
                                    </select>
                                </div>
                            </#if>

						</div>
					</div>
					<div class="box-footer" style="text-align:right;">
						<button type="submit" class="btn btn-primary"
						>确定</button>
						<button type="button" class="btn btn-default mcmodalcancle"
								data-dismiss="modal">取消</button>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>
</body>

<#include "/common/modalTip.ftl"/>
<script type="text/javascript">

	$(".deptselect").on("change",function(){
		//alert("部门选择变化");
		var selectdeptid = $(this).val();

		$.post("selectdept",{selectdeptid:selectdeptid},function(data){
			$(".positionselect").empty();

			//console.log(data);
			$.each(data,function(i,item){
				var potion = $("<option value="+item.positionId+">"+item.name+"</option>");
				$(".positionselect").append(potion);
			});
		});

	});

	$(".usermanagechange").click(function(){
		var userid = $(this).siblings(".deptuserid").val();
		console.log(userid);
		$("#thismodal.userchange").modal("toggle");
		$('#thismodal.userchange .modal-body').css('display', 'block');
		$("#thismodal .changeuser .changeuserid").val(userid);

	});

	$(".changemanage").click(function(){
		$("#thismodal.managechangemodel").modal("toggle");
		$('#thismodal.managechangemodel .modal-body').css('display', 'block');
	});




	/*  $('.successToUrl').on('click',function(){
        window.location.href='/testsysmenu';
    }); */

	function alertCheck(errorMess){

		$('.alert-danger').css('display', 'block');
		// 提示框的错误信息显示
		$('.error-mess').text(errorMess);

	}
	//表单提交前执行的onsubmit()方法；返回false时，执行相应的提示信息；返回true就提交表单到后台校验与执行
	function check() {
		console.log("开始进入了");
		//提示框可能在提交之前是block状态，所以在这之前要设置成none
		$('.alert-danger').css('display', 'none');
		var isRight = 1;
		$('.form-control').each(function(index) {
			// 如果在这些input框中，判断是否能够为空
			if ($(this).val() == "") {
				// 排除哪些字段是可以为空的，在这里排除
				if (index == 2 || index == 3 || index == 4 || index == 5 || index == 6) {
					return true;
				}
				// 获取到input框的兄弟的文本信息，并对应提醒；
				var brother = $(this).siblings('.control-label').text();
				var errorMess = "[" + brother + "输入框信息不能为空]";
				// 对齐设置错误信息提醒；红色边框
				$(this).parent().addClass("has-error has-feedback");
				$('.alert-danger').css('display', 'block');
				// 提示框的错误信息显示
				$('.error-mess').text(errorMess);
				// 模态框的错误信息显示
				$('.modal-error-mess').text(errorMess);
				isRight = 0;
				return false;
			} else {

				if(index == 0){
					var $name=$(this).val();

					if(isChinaName($name) == false){
						$(this).parent().addClass("has-error has-feedback");
						alertCheck("请输入中文名称");
						isRight = 0;
						return false;
					}
				}

				if(index == 3){
					var $mail=$(this).val();

					if(isMailNo($mail) == false){
						$(this).parent().addClass("has-error has-feedback");
						alertCheck("邮箱格式错误");
						isRight = 0;
						return false;
					}
				}
				// 在这个里面进行其他的判断；不为空的错误信息提醒
				return true;
			}
		});
		if (isRight == 0) {
			//modalShow(0);
			return false;
		} else if (isRight == 1) {
			//modalShow(1);
			return true;
		}
//	return false;
	}


	//验证中文名称
	function isChinaName(name) {
		var pattern = /^[\u4E00-\u9FA5]{1,6}$/;
		return pattern.test(name);
	}

	//验证邮箱
	function isMailNo(mail){
		var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
		return pattern.test(mail);
	}
</script>
</html>